#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

/* node in conflict list */
typedef struct l_node {
	int value;
	struct l_node *next;
} l_node_t;

/* node in hash table */
typedef struct t_node {
	int value;
	/* valie == 1, value is valid
	 * else value is not valid (eg: deleted)
	 */
	int valid;
	l_node_t *list;
} t_node_t;

/* hash talble */
typedef struct hash {
	int s; 		/* size */
	t_node_t *arr;
}hash_t;

/* to init hash table */
int init_hash(hash_t *h, int n)
{
	t_node_t *p = NULL;
	p = (t_node_t *)malloc(sizeof(t_node_t) * n);
	if (p == NULL)
		return -1;
	memset(p, 0, sizeof(t_node_t) * n);
	h->arr = p;
	h->s = n;
	return 0;
}

int insert_hash(hash_t *h, int d)
{
	int ret = 0, index = d % h->s;
	l_node_t *p;
	
	/* if value is invalid, insert data here */
	if(h->arr[index].valid == 0) {
		h->arr[index].value = d;
		h->arr[index].valid = 1;
	} else { /* insert data by conflict list */
		p = (l_node_t *)malloc(sizeof(l_node_t));
		if (p == NULL) {
			ret = -1;
		} else {
			p->value = d;
			p->next = h->arr[index].list;
			h->arr[index].list = p;
		}
	}

	return ret;
}

/*
 *return: 0 success, -1 not found
 */
int delete_hash(hash_t *h, int d)
{
	int ret = -1, index = d % h->s;
	l_node_t *p, *q;

	/* if the fist data is d, set it invalid */
	if (h->arr[index].valid == 1 
		&& h->arr[index].value == d)  {
		ret = 0;
		h->arr[index].valid = 0;
	}
	/* look for the data in conflict list */
	for (q = p = h->arr[index].list; p != NULL; q = p, p = p->next) {
		if (p->value != d)
			continue;

		if (p == h->arr[index].list) { 	/* fist node */
			h->arr[index].list = p->next;
		} else { /* not the first node */
			q->next = p->next;
		}
		free(p);
		ret = 0;
		break;
	}
	return ret;
}

void print_hash(hash_t *h)
{
	int i;

	for (i = 0; i < h->s; i++) {
		l_node_t *p = NULL;

		printf("sub num is %d:\t", i);
		if (h->arr[i].valid == 1)
			printf("%d ", h->arr[i].value);
		for (p = h->arr[i].list; p != NULL; p = p->next)
			printf("%d ", p->value);

		printf("\n");
	}
}
void destroy_hash(hash_t *h)
{
	int i;

	for (i = 0; i < h->s; i++) {
		l_node_t *q, *p = h->arr[i].list;
		while (p != NULL) {
			q = p->next;
			free(p);
			p = q;
		}
	}
	free(h->arr);
}

/*
int main()
{
	hash_t h[1];
	int i, n = 7;
	int data[] = {10, 12, 13, 18, 9, 7, 4, 34, 43, 5, 3, 0, 57, 16};

	init_hash(h, n);	

	for (i = 0; i < 14; i++) {
		insert_hash(h, data[i]);
	}
	print_hash(h);

	printf("\n");
	delete_hash(h, 10);
	delete_hash(h, 7);
	insert_hash(h, 21);
	print_hash(h);
	
	destroy_hash(h);

	return 0;
}
*/

int main() 
{
	hash_t h[1];
	int i, n, data = 0, flag;
	char str[100];

	scanf("%d", &n);
	init_hash(h, n);
	scanf("%s", str);
	
	i = 0;
	while (1) {
		if (isdigit(str[i])) {
			data *= 10;
			data += str[i] - '0';
		} else if (str[i] == ',' || str[i] == '\0') {
			insert_hash(h, data);
			data = 0;
		} else {
			printf("error input\n");
			return -1;
		}
		if (str[i] == '\0')
			break;
		i++;
	}
	
	while (scanf("%s", str)) {
		if (strcmp(str, "p") == 0)
			print_hash(h);
		else {
			i = 0;
			data = 0;
			while(1) {
				if(str[i] == '-')
					flag = 0;
				else if(str[i] == '+')
					flag = 1;
				else if (str[i] == ',' || str[i] == '\0') {
					if (flag) {
						insert_hash(h, data);
					} else {
						delete_hash(h, data);
					}
					data = 0;
				} else if (isdigit(str[i])){
					data *= 10;
					data += str[i] - '0';
				} else {
					printf("error input\n");
					return -1;
				}
				if (str[i] == '\0')
					break;
				i++;
			}
		}
	}
	
	destroy_hash(h);
	return 0;
}

